# Copyright 2014 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Test classes for code snippet for modeling article."""

import pytest

import keyproperty_models as models


def test_models(testbed):
    name = 'Takashi Matsuo'
    contact = models.Contact(name=name)
    contact.put()
    contact = contact.key.get()
    assert contact.name == name


# This test fails because of the eventual consistency nature of
# HRD. We configure HRD consistency for the test datastore stub to
# match the production behavior.
@pytest.mark.xfail
# [START failing_test]
def test_fails(self):
    contact = models.Contact(name='Example')
    contact.put()

    models.PhoneNumber(
        contact=self.contact_key,
        phone_type='home',
        number='(650) 555 - 2200').put()
    numbers = contact.phone_numbers.fetch()
    assert 1 == len(numbers)
# [END failing_test]
